package sq.repository;


import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import sq.dao.Food;

import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;

/**
 * sunquan
 *
 */
public interface FoodRepository extends JpaRepository<Food,Integer> {
   //更新菜品
    @Transactional
    @Modifying
    @Query(value = " UPDATE Food f SET f.foodName = :newName," +
            "f.foodType = :newType,f.price=:newPrice," +
            "f.calorie=:newCalorie,f.remarks=:newRemarks," +
            "f.updateTime=:newTime WHERE f.foodId = :foodId")
    Integer updateFoodByFoodId(@Param("newName") String newName,
                               @Param("newType") Integer newType,
                               @Param("newPrice") Double newPrice,
                               @Param("newCalorie") Integer newCalorie,
                               @Param("newRemarks") String newRemarks,
                               @Param("foodId") Integer foodId,
                               @Param("newTime") Date newTime);

    //按条件查询菜品
    List<Food> findFoodByFoodTypeAndAndFoodNameLike(int foodType,String foodName);

    List<Food> findFoodByFoodNameLike(String foodName);
}
